﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using ServiceStack;
using ServiceStack.ServiceInterface;
namespace Pacs.Services.Soa
{

    [DataContract]
    public class DTORequest<T>
    {
        ///// <summary>
        ///// 请求的头信息（与http头含义不同），通常为请求的配置信息
        //// </summary>
        /// 消息来源的可信任性
        /// </summary>
        [DataMember(Name = "header")]
        public DTORequestHeader Header
        { get; set; }
        /// <summary>
        /// 请求的业务主体对象
        /// </summary>
        [DataMember(Name = "body")]
        public T Body
        { get; set; }
        public DTORequest()
        {
            var ss = this.Header;
        }
        private RequestUser _user;

        public RequestUser User
        {
            get { return _user; }
            set { _user = value; }
        }

        public virtual void DoAssert()
        {

        }
        public bool Verification(DTORequest<T> request)
        {
            return true;
            //加密方式  yonghuming  +  @  + mima  
            try
            {
                //var ss = DySys.JiaMi.Des.DESDecrypt(request.Header.Creditability, request.Header.Source, request.Header.Source);
                //var userName = ss.Split('@')[0];
                //var pwd = ss.Split('@')[1];
                //if (this._user==null)
                //{
                //    _user = new RequestUser();
                //    _user.Password = pwd;
                //    _user.source = request.Header.Source;
                //    _user.RequestTime = DateTime.Now;
                //    _user.Version = request.Header.Ver;
                //    _user.UserName = userName;
                //}
                //if(_user.UserName==userName&&_user.Password==pwd&&_user.source== request.Header.Source)
                //{
                //    return true;
                //}
                //return false;
                //if ((DateTime.Now - _user.RequestTime).TotalSeconds > int.Parse(System.Configuration.ConfigurationManager.AppSettings["RequestExpired"]))
                //{
                //}
              
                //RequestExpired
            }
            catch (Exception ex)
            {
                return false;
            }


            return false;
        }
    }

   [DataContract]
    public class DTORequestHeader
    {
        /// <summary>
        /// 版本
        /// </summary>
        [DataMember(Name = "ver")]
        public string Ver
        {
            get;
            set;
        }
        /// <summary>
        /// 访问方法
        /// </summary>
        [DataMember(Name = "method")]
        public string Method
        {
            get;
            set;
        }
        /// <summary>
        /// 来源的渠道
        /// </summary>
        [DataMember(Name = "source")]
        public string Source
        {
            get;
            set;
        }
        /// <summary>
        /// 用户身份验证信息
        /// </summary>
        [DataMember(Name = "creditability")]
        public string Creditability
        {
            get;
            set;
        }
    }

}
